package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Description:
 *
 * @Author: xiongzhenhui
 * @Create: 2025/8/12 9:50
 * @Version: 1.0
 */
@RestController
public class OrderInfoController {
    @Autowired
    OrderInfoService orderInfoService;
    @RequestMapping("/getOrderInfoByDq")
    public JSONObject getOrderInfoByDq(){
        List<Map> list = orderInfoService.getOrderInfoByDq();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray mapData = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("name"));
            jsonObject1.put("value",map.get("origin_amount"));
            JSONArray tooltipValues = new JSONArray();
            tooltipValues.add(map.get("order_people"));
            tooltipValues.add(map.get("order_num"));
            jsonObject1.put("tooltipValues",tooltipValues);
            mapData.add(jsonObject1);
        }
        data.put("mapData",mapData);
        data.put("valueName","订单总额");

        JSONArray tooltipNames = new JSONArray();
        tooltipNames.add("下单人数");
        tooltipNames.add("订单数");
        data.put("tooltipNames",tooltipNames);

        JSONArray tooltipUnits = new JSONArray();
        tooltipUnits.add("人");
        tooltipUnits.add("单");
        data.put("tooltipUnits",tooltipUnits);
        jsonObject.put("data",data);
        return jsonObject;
    }

    @RequestMapping("/getOrderInfoByKs")
    public JSONObject getOrderInfoByKs(){
        List<Map> list = orderInfoService.getOrderInfoByKs();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();

        JSONObject col1 = new JSONObject();
        col1.put("name","课程名称");
        col1.put("id","course_name");
        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","考试人次");
        col2.put("id","num");
        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","平均分");
        col3.put("id","avg_score");
        columns.add(col3);

        JSONObject col4 = new JSONObject();
        col4.put("name","平均时长");
        col4.put("id","avg_time");
        columns.add(col4);
        data.put("columns",columns);

        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("course_name",map.get("course_name"));
            row.put("num",map.get("num"));
            row.put("avg_score",map.get("avg_score"));
            row.put("avg_time",map.get("avg_time"));
            rows.add(row);
        }
        data.put("rows",rows);
        jsonObject.put("data",data);
        return jsonObject;
    }

    @RequestMapping("/getOrderInfoByRs")
    public JSONObject getOrderInfoByRs(){
        List<Map> list = orderInfoService.getOrderInfoByRs();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        for (Map map : list) {
            jsonObject.put("data",map.get("num"));
        }
        return jsonObject;
    }

    @RequestMapping("/getOrderInfoByPj")
    public JSONObject getOrderInfoByPj(){
        List<Map> list = orderInfoService.getOrderInfoByPj();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject data = new JSONObject();
        JSONArray columns = new JSONArray();

        JSONObject col1 = new JSONObject();
        col1.put("name","课程名称");
        col1.put("id","course_name");
        columns.add(col1);

        JSONObject col2 = new JSONObject();
        col2.put("name","平均评分");
        col2.put("id","avg_stars");
        columns.add(col2);

        JSONObject col3 = new JSONObject();
        col3.put("name","评价人数");
        col3.put("id","num");
        columns.add(col3);

        JSONObject col4 = new JSONObject();
        col4.put("name","好评人数");
        col4.put("id","hp_num");
        columns.add(col4);

        JSONObject col5 = new JSONObject();
        col5.put("name","好评率");
        col5.put("id","hpl");
        columns.add(col5);

        data.put("columns",columns);

        JSONArray rows = new JSONArray();
        for (Map map : list) {
            JSONObject row = new JSONObject();
            row.put("course_name",map.get("course_name"));
            row.put("avg_stars",map.get("avg_stars"));
            row.put("num",map.get("num"));
            row.put("hp_num",map.get("hp_num"));
            row.put("hpl",map.get("hpl"));
            rows.add(row);
        }
        data.put("rows",rows);
        jsonObject.put("data",data);
        return jsonObject;
    }
}
